4. WhatsApp Receive Message Flow
This section outlines the end-to-end process of receiving and handling incoming WhatsApp events within the ViSN platform.
1. Webhook Configuration and Initial Request Handling
Webhook Setup
- The WhatsApp webhook is configured as a gateway endpoint:
/:version/webhooks/whatsapp/webhook
- This endpoint is part of the repair-serve-api service and acts as the entry point for all incoming WhatsApp events.
Request Validation and Forwarding in repair-serve-api
- Validation:
- The incoming request is validated to ensure it contains a valid WhatsApp event.
- Only text messages, status updates and reaction events are processed, other event types are ignored.
- Logging:
- The raw webhook data is logged for tracking purposes.
- Forwarding:
- Once validated, the complete payload is forwarded to repair-serve-callable for further processing.
2. Processing in repair-serve-callable
- Event Reception:
- The repair-serve-callable service receives the forwarded WhatsApp event.
- Cloud Task Enqueueing:
- A Cloud Task is enqueued to ensure asynchronous processing.
- The task is added to the
whatsapp-messages-queue
with the processing endpoint:/webhook-listeners/whatsapp
3. Queue Processing in queue-services
Task Retrieval
The /webhook-listeners/whatsapp
endpoint in the queue-services picks up the task.
Event Processing
- Extracts the
from
andto
phone numbers from the event payload. - Identifies the WhatsApp message tracking document from ancillary DB:
/whatsapp/lease/<leasePhoneNumber>/{id}
- This document contains the necessary details to derive the reference for updating chat records.
Message Handling
-
Updates the corresponding Firestore document:
/leasecompany/{leaseId}/enquiries/{enquiryId}/whatsapp/messages/chatMessages/{messageId}
-
Text Messages:
- A new document is created in the chat record.
- The unread message count is incremented.
-
Reactions:
- The referenced message is identified.
- Reaction details are appended to the existing record.
-
Status Updates:
- The referenced message is identified.
- The status in the existing record is updated.
4. Error Handling and Logging
-
Error Logging:
-
If no active tracking record is found for a received message, the event is logged and skipped.
-
Monitoring:
-
All processed events are logged for debugging and monitoring purposes, ensuring traceability throughout the workflow.
Status: Draft (Pending Review)
Category: Protected
Authored By: Sohan on March 04, 2025